//package ltd.followkba.comment.utils;
//
//import java.util.Calendar;
//import java.util.Date;
//
//import ltd.followkba.comment.bean.BOldCommDone;
//import ltd.followkba.comment.bean.BOldRankInfo;
//import ltd.followkba.comment.bean.BSongInfo;
//import ltd.followkba.comment.bean.BTaskRun;
//import ltd.followkba.comment.MKCS;
//import ltd.followkba.comment.MUTIL;
//import ltd.followkba.comment.ResultNet;
//import main.MAPI;
//
//import static main.MAPI.mMyUtils;
//import static ltd.advskin.MSKIN.MSTRING;
//import static ltd.followkba.comment.MKCC.cKCB_SW_HAOCHANG;
//import static ltd.followkba.comment.utils.DbsTypeUserID.TASK_ACCOUNT;
//import static ltd.followkba.comment.utils.DbsTypeUserID.USER_DETAIL;
//import static ltd.advskin.MSKIN.MLOGE;
//import static main.MAPI.MSLEEP;
//import static ltd.advskin.MSKIN.MSTRING;
//import static ltd.advskin.MSKIN.MTOAST;
//
///**
// * Created by Administrator on 2018/6/23.
// */
//
//public class CWriteComment {
//    public void startTask(BTaskRun bTaskRun){
//        long timeMillis = System.currentTimeMillis();
//        byte appType = bTaskRun.AppType;
//        BOldRankInfo bRankInfo = getNextUser(bTaskRun);
//        if (bRankInfo != null){
//            MKCS.gsWorkStatus[appType] = String.format("%s榜(%d/%d/%d) ", MKCS.gsRankName[appType], 0, MKCS.gRankIndex[appType], MKCS.mKcBRankInfo[appType].size());
//            boolean[] isNewSong = new boolean[1];
//            String commentID = "";
//            if (bTaskRun.OwnInfoTime == 0){
//                 bTaskRun.mOwnDetail = bTaskRun.OwnApp.GetUserFullInfo(bTaskRun.OwnApp.gsUserID);
//                if (bTaskRun.mOwnDetail != null) {
//                    bTaskRun.OwnApp.downloadHeadFile(bTaskRun.mOwnDetail);
//                    MBAPP.setUserDetail(bTaskRun.AppType, bTaskRun.OwnApp.gsUserID, bTaskRun.mOwnDetail);
////                    MSTRING(String.format("CWriteComment startTask B %d %s", MAPI.GET_FILE_LENGTH(bTaskRun.mOwnDetail.HeadFile), bTaskRun.mOwnDetail.HeadFile));
//                }
//            }
//            BSongInfo bSongInfo = bTaskRun.OwnApp.GetSongInfo(bRankInfo.SongID);
//            if (bSongInfo != null) {
//                commentID = bSongInfo.commentID;
//            }
//            String commentText = TaskGetCommentText(bTaskRun, bSongInfo, isNewSong);
////MSTRING("评论："+MUTIL.SHOW_DATE_FULL(MAPI.STRING_DEC32(bTaskRun.CntInfo.NewWorks.CreateTime)) + " "+gsLocal_1 + "_"+bTaskRun.StepTime);
//
//            String gsLocal_1 = bTaskRun.OwnApp.PutCommentToSong(bRankInfo.UserID, bRankInfo.SongID, commentID, commentText);
//            MSTRING(String.format("putCommentToSong A %s %s %s %s %s %s", bRankInfo.UserID, bRankInfo.SongID, bRankInfo.UserName, bRankInfo.SongName, commentText, gsLocal_1));
//            if ("ok".equals(gsLocal_1)) {
//                if (appType == cKCB_SW_HAOCHANG){
//                    bTaskRun.TaskResult = String.format("%s(%s)%s %s", bRankInfo.UserName, bRankInfo.UserID, MUTIL.FIX_STRING_LENGTH(bRankInfo.SongName, 6), commentText);
//                }
//                else {
//                    bTaskRun.TaskResult = String.format("%s %s %s", MUTIL.FIX_STRING_LENGTH(bRankInfo.UserName, 5), MUTIL.FIX_STRING_LENGTH(bRankInfo.SongName, 6), commentText);
//                }
//                ++bTaskRun.SuccessQty;
//                DbsTypeUserID dbsTypeUserID = new DbsTypeUserID(TASK_ACCOUNT, bTaskRun.AppType);
//                dbsTypeUserID.setMemoryInt("SuccessQty", bTaskRun.SuccessQty);
//                ++MKCS.g4SucessCounter;
//                DbsTypeUserID mainUserID = new DbsTypeUserID(USER_DETAIL, 9);
//                mainUserID.setMemoryInt("g4SucessCounter", MKCS.g4SucessCounter);
//                if (++bTaskRun.OwnInfoTime > 20) {         // 更新自己的信息
//                    bTaskRun.OwnInfoTime = 0;
//                    gsLocal_1 = bTaskRun.OwnApp.FetchFlower();
//                }
//                if (bTaskRun.mBAccount.IsAutoCare){
//                    MSTRING(String.format("bSongInfo.commentQty A %s %d", bSongInfo.commentQty, bTaskRun.mBAccount.AutoCareCommQty));
////                    GetUserFullInfo
//                    if (MAPI.STRING_DEC32(bSongInfo.commentQty) > bTaskRun.mBAccount.AutoCareCommQty){
//                        gsLocal_1 = bTaskRun.OwnApp.AddCareUser(bRankInfo.UserID);
//                        bTaskRun.TaskResult = String.format("自动关注： %s(%s) %s", bRankInfo.UserName, bRankInfo.UserID, gsLocal_1);
//                    }
//                }
//                if (isNewSong[0]){
//                }
//                BOldCommDone bCommDone = cloneBRankInfo(bRankInfo, commentText,(int)(System.currentTimeMillis() - timeMillis));
//                bCommDone.Source = MKCS.gsWorkStatus[bTaskRun.AppType];
//                MBAPP.setCommDone(appType, bTaskRun.OwnApp.gsUserID, bCommDone);
//            } else {
//                if (bTaskRun.AppType == cKCB_SW_HAOCHANG){
//                    if (gsLocal_1.indexOf("拉黑") >= 0) {             // 您已被拉黑，不能进行该操作
//                        BOldCommDone bCommDone = cloneBRankInfo(bRankInfo, "", 0);
//                        MBAPP.setCommDone(appType, bTaskRun.OwnApp.gsUserID, bCommDone);
//                    }
//                    bTaskRun.TaskResult = String.format("评错：%s(%s)%s %s %s ", bRankInfo.UserName, bRankInfo.UserID, MUTIL.FIX_STRING_LENGTH(bRankInfo.SongName, 6), MUTIL.FIX_STRING_LENGTH(commentText, 6), gsLocal_1);
//                }
//                else {
//                    bTaskRun.TaskResult = String.format("错：%s%s %s %s ", MUTIL.FIX_STRING_LENGTH(bRankInfo.UserName, 5), MUTIL.FIX_STRING_LENGTH(bRankInfo.SongName, 6), MUTIL.FIX_STRING_LENGTH(commentText, 6), gsLocal_1);
//                }
//                if (gsLocal_1.indexOf("账号") >= 0) {       // 你的账号已经被封禁，如有疑问请联系唱吧客服:
//                    bTaskRun.mBAccount.AccountStatus = gsLocal_1;
//                    bTaskRun.mBAccount.IsPause = true;
//                    MBAPP.setTaskAccount(bTaskRun.AppType, bTaskRun.mBAccount);
//                }
//            }
//        }else {
//            MTOAST(String.format("读出%s榜单数据出错！ ", MUTIL.GET_APP_TYPE_NAME(appType)));
//        }
//        bTaskRun.IsBusy = false;
//        bTaskRun.StepCounter = 0;
//    }
//    private BOldCommDone cloneBRankInfo(BOldRankInfo bRankInfo, String text, int timer){
//        BOldCommDone bCommDone = new BOldCommDone();
//        bCommDone.UserID = bRankInfo.UserID;
//        bCommDone.SongID = bRankInfo.SongID;
//        bCommDone.UserName = bRankInfo.UserName;
//        bCommDone.SongName = bRankInfo.SongName;
//        bCommDone.SetTick = mMyUtils.getCurrentDate();
//        bCommDone.Text = text;
//        bCommDone.RunTimer = timer;
//        return bCommDone;
//    }
//    public BOldRankInfo getNextUser(BTaskRun bTaskRun){
//        byte appType = bTaskRun.AppType;
//        int index = 0;
//        boolean skipNextRank = false;
//        MSTRING("getNextUser A "+appType);
//        while (!MKCS.isSystemClose) {
//            if (skipNextRank || MKCS.mKcBRankInfo[appType] == null) {                  // 还没有榜数据
//                ResultNet resultNet = bTaskRun.OwnApp.GetRankList();
//                if (resultNet.result != null) {
//                    MKCS.gsRankName[appType] = resultNet.message;
//                    MKCS.mKcBRankInfo[appType] = resultNet.result;
//                    MKCS.gRankIndex[appType] = 0;
//                }
//            }
//            if (MKCS.mKcBRankInfo[appType] != null) {
//                index = MKCS.gRankIndex[appType]++;
//                if (index < MKCS.mKcBRankInfo[appType].size()){
//                    BOldRankInfo bRankInfo = MKCS.mKcBRankInfo[appType].get(index);
//                    if (!MBAPP.isExistCommDone(appType, bTaskRun.OwnApp.gsUserID, bRankInfo)){
//                        return bRankInfo;
//                    }
//                }
//            }
//            skipNextRank = true;      // 可能有问题了，跳下一个榜
//            MSLEEP(1000);
//            MLOGE("writeComment B "+appType+" "+ index+" "+(MKCS.mKcBRankInfo[appType]!=null?MKCS.mKcBRankInfo[appType].size():0));
//        }
//        MLOGE("writeComment C "+ MKCS.mKcBRankInfo[appType]);
//        return null;
//
//    }
//
//    public String TaskGetCommentText(BTaskRun bTaskRun, BSongInfo bSongInfo, boolean[]NewWorks){
//        long NowTime = (System.currentTimeMillis()/1000);
//        String gsLocal_1 = "";
//        NewWorks[0] = false;
//        if (bTaskRun !=null && bSongInfo != null) {
//            if (MKCS.g4NewCommTime > 0 && !"".equals(MKCS.gsNewComment)) {
//                if (TimeAddSettingHour(bSongInfo.createTime, MKCS.g4NewCommTime) > NowTime) {
//                    gsLocal_1 = MKCS.gsNewComment;
//                    NewWorks[0] = true;
//                }
//            }
//            if ("".equals(gsLocal_1)) {
//                if (MKCS.g4OldCommTime > 0 && !"".equals(MKCS.gsOldComment)) {
//                    if (TimeAddSettingHour(bSongInfo.createTime, MKCS.g4OldCommTime * 24) < NowTime) {
//                        gsLocal_1 = MKCS.gsOldComment;
//                    }
//                }
//            }
//        }
//        if ("".equals(gsLocal_1)){
//            gsLocal_1 = MKCS.gsNormalComment;
//        }
//        ++bTaskRun.CommentStep;
//        String[] params = gsLocal_1.split("\n");
//        if (params.length > 0){
//            gsLocal_1 = params[bTaskRun.CommentStep % params.length];
//            gsLocal_1 = gsLocal_1.replace("\r", "");
//            StringBuffer outString = new StringBuffer();
//            int g4Local_1 = 0;
//            int g4Local_2;
//            char g2Local_1;
//            while (g4Local_1 < gsLocal_1.length()){
//                g2Local_1 = gsLocal_1.charAt(g4Local_1);
//                if (g2Local_1 == '='){
////                    MSTRING("评论1："+g4Local_1);
//                    g4Local_2 = MUTIL.GET_FACE_STRING(bTaskRun.FaceStep);
//                    outString.append((char)(g4Local_2 >> 16));
//                    g4Local_2 = g4Local_2 & 0xffff;
//                    if (g4Local_2 > 0){
//                        outString.append((char)g4Local_2);
//                    }
//                    ++bTaskRun.FaceStep;
//                }
//                else {
//                    outString.append(g2Local_1);
//                }
//                ++g4Local_1;
//            }
////            MSTRING("评论2："+new String(outString));
//            return new String(outString);
////            String gsLocal_2 = new String(outString);
////            if (bTaskRun.CntInfo != null && bTaskRun.CntInfo.NewWorks != null) {
////                MSTRING("评论1：" + bTaskRun.CntInfo.UserName + " " + bTaskRun.CntInfo.NewWorks.WorksName + " " + gsLocal_1 + " " + gsLocal_2);
////            }
////            else {
////                MSTRING("评论2：" + gsLocal_1 + " " + gsLocal_2);
////            }
////            return gsLocal_2;
//        }
//        return "";
//    }
//    private static int TimeAddSettingHour(String intTime, int addHour){
//        Calendar calendar = Calendar.getInstance();
//        long g4Local_1 = MAPI.STRING_DEC32(intTime);
//        calendar.setTime(new Date(g4Local_1 * 1000 ));
//        calendar.add(Calendar.HOUR_OF_DAY, addHour);
//        return (int)(calendar.getTimeInMillis() /1000);
//    }
//}
